package com.java.yz.day12.ketang;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/*
    HashMap类概述
        键是哈希表结构，可以保证键的唯一性
    HashMap案例
        HashMap<String,String>
        HashMap<Integer,String>
        HashMap<String,Student>
        HashMap<Student,String>

 */

public class HashMapDemo1 {
    public static void main(String[] args) {
        //创建集合对象
        HashMap<Student, String> Map = new HashMap<Student, String>();
        //添加集合元素
        Map.put(new Student("柳宗元",20),"看诗");
        Map.put(new Student("李清照",23),"读诗");
        Map.put(new Student("白居易",22),"想诗");
        Map.put(new Student("杜甫",26),"吟诗");
        Map.put(new Student("李白",24),"写诗");
        Map.put(new Student("李白",20),"写诗");
        //遍历集合
        Set<java.util.Map.Entry<Student, String>> entries = Map.entrySet();
        for (java.util.Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String name = key.getName();
            int age = key.getAge();
            String value = entry.getValue();
            System.out.println(name+"=="+age+"=="+value);
        }
        //他的迭代顺序是随机的，输入输出不一致
    }
}
